﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HCMServices.DTO;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Data.Linq;
using System.Collections;
using System.Collections.Generic;

namespace HCMServices.DAO
{
    /// <summary>
    /// This class process for TENDIADIEM Table
    /// </summary>
    public class PlaceNameDAO
    {
        private MyDataContext db;

        /// <summary>
        /// Constructor of class
        /// </summary>
        /// <param name="stringConnect">String indentify how to connect database</param>
        public PlaceNameDAO(string stringConnect)
        {
            db = new MyDataContext(stringConnect);
        }

        /// <summary>
        /// This function search TENDIADIEM rows base on ID Column 
        /// </summary>
        /// <param name="id">ID wants to find</param>
        /// <returns>TENDIADIEM rows if id was found or null</returns>
        public PlaceNameDTO Search(int id)
        {
            PlaceNameDTO tenDiaDiemDTO = new PlaceNameDTO();

            IList<TENDIADIEM> query = (from TENDIADIEM tdd in db.PlaceName
                                       where tdd.MaTenDiaDiem == id
                                       select tdd).ToList();

            foreach (TENDIADIEM tdd in query)
            {
                tenDiaDiemDTO.Id = tdd.MaTenDiaDiem;
                tenDiaDiemDTO.Name = tdd.TenDiaDiem1;

                return tenDiaDiemDTO;                       
            }

            return null;                                    
        }

        /// <summary>
        /// This function gets all TENDIADIEM rows in database
        /// </summary>
        /// <returns>List of TENDIADIEM rows</returns>
        public List<PlaceNameDTO> GetAllPlaceNameDTO()
        {
            List<PlaceNameDTO> lstTenDiaDiemDTO = new List<PlaceNameDTO>();

            IList<TENDIADIEM> query = (from TENDIADIEM dd in db.PlaceName
                                   select dd).ToList();

            foreach (TENDIADIEM dd in query)
            {
                PlaceNameDTO temp = new PlaceNameDTO();
                temp.Id = dd.MaTenDiaDiem;
                temp.Name = dd.TenDiaDiem1;

                lstTenDiaDiemDTO.Add(temp);
            }

            return lstTenDiaDiemDTO;
        }
    }
}
